using System;
using SimpleCore;
using UnityEditor;
using UnityEngine;

namespace SimpleEditor
{
    public class EditorGUI
    {
        public static void DrawSelectFolder(SerializedProperty property, GUIStyle guiStyle)
        {
            EditorGUILayout.BeginHorizontal();
            
            if (GUILayout.Button(property.name, guiStyle))
            {
                var path = EditorUtility.OpenFolderPanel($"Select {property.name}", PathTool.GetFullPath(property.stringValue),
                    "");
                property.stringValue = PathTool.GetAssetPath(path);
            }
            GUILayout.Label(property.stringValue);
            
            EditorGUILayout.EndHorizontal();
        }

        public static void DrawButton(string buttonName, Action onBtnClick, GUIStyle guiStyle = null)
        {
            if (guiStyle == null)
            {
                if (GUILayout.Button(buttonName))
                {
                    onBtnClick?.Invoke();
                }
                return;
            }
            
            if (GUILayout.Button(buttonName, guiStyle))
            {
                onBtnClick?.Invoke();
            }
        }
    }
}